<template>
    <div v-loading="loading" style="width: 100%;height: 100vh;" element-loading-text="正在校验身份，请稍后...">
    </div>
</template>

<script setup>
import { onMounted, ref } from 'vue';
import { useRoute, useRouter } from "vue-router";
import { OALoginapi } from '@/api/OAlogin';

import { useUserStore } from '@/pinia/modules/user'

const router = useRouter();
const route = useRoute();

let loading = ref(true)


onMounted(() => {

    // 获取当前页面的 URL
    var url = window.location.href;

    // 创建一个 URL 对象
    var urlObj = new URL(url);

    // 使用 URLSearchParams 对象来解析查询字符串
    var params = new URLSearchParams(urlObj.search);

    // 获取参数值
    var header = params.get('header');
    var token = params.get('token');

    // 输出参数值
    var url2 = urlObj.href;
    //var url2 = window.location.herf
    var temp2 = url2.split('?')[1];
    var pram2 = new URLSearchParams('?' + temp2);
    var pram1 = new URLSearchParams('?' + temp2);
    console.log(pram1.get('header')); // 大数据

//     const loginFormData = reactive({
//   username: '',
//   password: '',
//   // captcha: '',
//   // captchaId: '',
//   // 安装了谷歌密钥后可以删除注释
//   // code:'',
// })
    if (pram2 && pram1) {
        const userStore = useUserStore()
        userStore.ClearStorage()
        let data = {
            token: pram2.get('token'),
            header: pram1.get('header')
        }
        OALoginapi(data).then(res => {
            if (res.code == 0) {
              
                const userStore = useUserStore()
                // const login = async () => {
                      userStore.OAlogin(res)
                // }
            }
            else{
                router.push({ path: `/login` })
            }
        }).catch(err => {
            router.push({ path: `/login` })}
        )

       
    }


});



</script>